package com.wisezone.HomeWork.home02;

import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.io.File;

public class TestStudent {
    public static void main(String[] args) {

        /**
         * 构造学生对象集合
         */
        List<Student> students =getStudents();

        File file = new File("Student.dat");
        try {
            OutputStream out = new FileOutputStream(file,false);
            ObjectOutputStream objectOutputStream = new ObjectOutputStream(out);
            objectOutputStream.writeObject(students);
        }catch (Exception e){
            e.printStackTrace();
        }


    }
    public static List<Student> getStudents(){
        String code=null;
        String name=null;
        SEX sex=SEX.Man;
        float score=0.0F;
        String isY = null;
        int intSex=0;
        Student student = null;
        List<Student> students=new ArrayList<>();
        Scanner scanner = new Scanner(System.in);
        while (true){
            System.out.println("输入学生学号:");
            code=scanner.next();
            System.out.println("输入学生姓名:");
            name=scanner.next();
            System.out.println("输入学生性别:(0/1)");
            intSex=scanner.nextInt();
            System.out.println("输入学生分数:");
            score=scanner.nextFloat();
            sex = intSex ==0?SEX.Man:SEX.Woman;
            student=new Student(code,name,sex,score);

            System.out.println("是否继续添加：（y/n）");
            isY=scanner.next();
            if (!"y".equals(isY)){
                break;
            }
        }
        scanner.close();
        return students;
    }
}
